package game;

import javax.swing.*;
import java.awt.*;

public class GameWindow extends JFrame {
    private CardLayout cardLayout;
    private JPanel mainPanel;

    private MainMenuPanel mainMenuPanel;
    private CharacterSelectPanel characterSelectPanel;
    private FightPanel fightPanel;
    private GameOverPanel gameOverPanel;
    private boolean isPaused = false;

    public static final boolean DEBUG_MODE = false; //TODO 调试模式，发布时可设为false

    public GameWindow() {
        setTitle("拳皇97");
        setSize(854, 480);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(false);
        setLocationRelativeTo(null);

        cardLayout = new CardLayout();
        mainPanel = new JPanel(cardLayout);

        mainMenuPanel = new MainMenuPanel(this);
        characterSelectPanel = new CharacterSelectPanel(this);

        // 添加暂停面板（初始不可见）
        PausePanel pausePanel = new PausePanel(this);
        mainPanel.add(pausePanel, "PAUSE");

        mainPanel.add(mainMenuPanel, "MAIN_MENU");
        mainPanel.add(characterSelectPanel, "CHARACTER_SELECT");



        add(mainPanel);
        switchToMainMenu();
        setVisible(true);
    }

    public void switchToMainMenu() {
        cardLayout.show(mainPanel, "MAIN_MENU");
        mainMenuPanel.requestFocusInWindow();
    }

    public void switchToCharacterSelect() {
        cardLayout.show(mainPanel, "CHARACTER_SELECT");
        characterSelectPanel.requestFocusInWindow();
    }

    public void startFight(String playerCharacter, String enemyCharacter) {
        if (fightPanel != null) {
            mainPanel.remove(fightPanel);
        }
        fightPanel = new FightPanel(this, playerCharacter, enemyCharacter);
        mainPanel.add(fightPanel, "FIGHT");
        cardLayout.show(mainPanel, "FIGHT");
        fightPanel.requestFocusInWindow();
    }

    public void pauseGame() {
        if (!isPaused) {
            isPaused = true;
            cardLayout.show(mainPanel, "PAUSE");
            fightPanel.pauseGame();
        }
    }

    public void resumeGame() {
        if (isPaused) {
            isPaused = false;
            cardLayout.show(mainPanel, "FIGHT");
            fightPanel.resumeGame();
        }
    }

    public void returnToMainMenu() {
        isPaused = false;
        cardLayout.show(mainPanel, "MAIN_MENU");
        // 可以添加清理战斗状态的代码
    }

    public void gameOver(boolean playerWon) {
        if (gameOverPanel != null) {
            mainPanel.remove(gameOverPanel);
        }
        gameOverPanel = new GameOverPanel(this, playerWon);
        mainPanel.add(gameOverPanel, "GAME_OVER");
        cardLayout.show(mainPanel, "GAME_OVER");
        gameOverPanel.requestFocusInWindow();
    }
}